#include <bits/stdc++.h>
using namespace std;
int T;
int n;
int a[200005];
long long dfs(int apos,int lastr,int lastb){
    if(apos>n)return 0;
    if(lastr==0)return dfs(apos+1,a[apos],lastb);
    if(lastb==0&&a[apos]!=lastr)return dfs(apos+1,lastr,a[apos]);

    if(a[apos]==lastr){
        return a[apos]+dfs(apos+1,a[apos],lastb);
    }
    if(a[apos]==lastb){
        return a[apos]+dfs(apos+1,lastr,a[apos]);
    }
    if(a[apos]!=lastr&&a[apos]!=lastb){
        return max(dfs(apos+1,a[apos],lastb),dfs(apos+1,lastr,a[apos]));
    }
}
int main(){
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    cin>>T;
    for(int i=1;i<=T;i++){
    memset(a,0,sizeof(a));
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }
    cout<<dfs(1,0,0)<<endl;
    }
return 0;
}
